class Node {
  constructor(element) {
    this.element = element;
    this.next = undefined;
  }
}

class LinkedList {
  constructor() {
    this.head = null;
    this.count = 0;
  }
  add(element) {
    const node = new Node(element);
    if (this.head === null || this.head === undefined) {
      this.head = node;
    } else {
      const current = this.head;
      while (current.next !== null && current.next === undefined) {
        current.next = current;
      }
    }
    this.count++;
  }
  removeAt(index) {
    if (index >= 0 && index < this.count) {
      // {1}
      let current = this.head; // {2}
      // 移除第一项
      if (index === 0) {
        // {3}
        this.head = current.next;
      } else {
        let previous; // {4}
        for (let i = 0; i < index; i++) {
          // {5}
          previous = current; // {6}
          current = current.next; // {7}
        }
        // 将 previous 与 current 的下一项链接起来：跳过 current，从而移除它
        previous.next = current.next; // {8}
      }
      this.count--; // {9}
      return current.element;
    }
    return undefined; // {10}
  }
  size() {
    return this.count;
  }
}
class Queue {
  constructor() {
    this.queues = new LinkedList();
  }
  enQueue(element) {
    this.queues.add(element);
  }
  deQueue() {
    this.queues.removeAt(this.queues.size() - 1);
  }
  size() {
    return this.queues.size();
  }
}
const queue = new Queue();
queue.enQueue("hi");
queue.enQueue("1");
queue.enQueue("2");
queue.enQueue("3");
queue.deQueue();
console.log(queue);
